$(function () {
    findAllGroup()
})

function findAllGroup() {
    let data=myAjax("/group/findAll","","get")
    data=data.list;
    let html='';
    for (let i=0;i<data.length;i++){
        html +='        <tr>\n' +
            '            <td>'+data[i].id+'</td>\n' +
            '            <td>'+data[i].code+'</td>\n' +
            '            <td>'+data[i].groupName+'</td>\n' +
            '            <td>'+data[i].teamLeaderName+'</td>\n' +
            '            <td>'+data[i].teamLeaderCode+'</td>\n' +
            '            <td>'+data[i].teamCount+'</td>\n' +
            '            <td>'+data[i].buildTime+'</td>\n' +
            '            <td>'+data[i].classroom+'</td>\n' +
            '            <td>'+data[i].stage+'</td>\n' +
            '            <td>'+data[i].coach+'</td>\n' +
            '            <td><input type="button" value="编辑" onclick="updataById('+data[i].id+')"><input type="button" value="删除" onclick="deleteById('+data[i].id+','+data[i].teamCount+')"></td>\n' +
            '        </tr>';
    }
    $("#groupFandAll").html(html);
}

function updataById(id) {
    localStorage.setItem("groupId",id);
    $('#middle-reght').load('../html/group/groupUpdate.html');
}

function deleteById(id,teamCount){
    let da={
        id:id,
        teamCount:teamCount,
    }
    let data=myAjax("/group/deleteById",da,"post");
    data=data.result;
    if (data==1){
        alert("删除成功！");
        $('#middle-reght').load('group/group.html');
    }else if(data==2){
        alert("删除失败,该小组还有人呢！");
    }else if(data==0){
        alert("删除失败！");
    }

}